<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 19-5-13
 * Time: 上午11:03
 */

namespace api\modules\collection\controllers;


use common\components\tools\Model;
use common\models\CollectionResultPush;
use common\models\CollectionTask;
use wodrow\yii\rest\Controller;

class BackController extends Controller
{
    /**
     * (4) 外呼结果推送
     * @desc get/post
     */
    public function actionResultPush()
    {
        $this->onlyDataOut = true;
        $json = \Yii::$app->request->rawBody;
        $arr = json_decode($json, true);
        $task = CollectionTask::findOne(['task_id' => $arr['taskId']]);
        $result_push = new CollectionResultPush();
        $result_push->task_id = $task->id;
        $result_push->push_at = time();
        $result_push->req_json = $json;
        $result_push->fdsf_path = isset($arr['fdsfPath'])?$arr['fdsfPath']:null;
        if (!$result_push->save()){
            return [
                'code' => 1,
                'message' => Model::getModelError($result_push),
            ];
        }
        return [
            'code' => 0,
            'message' => "",
        ];
    }
}